<?php

namespace app\api\controller\zi;

use app\api\model\ArticleM;
use app\api\service\ZiS;
use app\common\controller\Api;
use think\Validate;

class Info extends Api
{
    protected $noNeedLogin = 'index';
    protected $noNeedRight = 'index';

    public function index()
    {
        $validate = new Validate();
        if (!$validate->check(input(), [
            'xing' => 'require',
            'ming' => 'require',
        ])) {
            $this->error($validate->getError());
        }
        $xing    = input('xing');
        $ming    = input('ming');
        $info    = ZiS::info($xing, $ming);
        $user    = $this->auth->getUser();
        $content = '';
        if ($user && ($user['grade'] == 1 || $user['grade'] == 2 ) && $user['number'] != 0) {
            $arr     = array_column($info, 'bhs');
            $sum     = array_sum($arr);
            $content = ArticleM::where('title', $sum)->value('content');
            if (!$content) {
                $this->error('error content');
            }
        }
        $this->success('', [
            'info'    => $info,
            'content' => ZiS::format($content),
            'price'   => config('site.ddgm'),
        ]);
    }
}
